package vodoo.gui.video;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import vodoo.tools.InetTools;
import vodoo.video.VideoStream;

public class VideoInfoPanel extends JPanel {
	//--------------------------------------------------------- CONSTANTES --//
	//---------------------------------------------------------- ATTRIBUTS --//
	
	private PreviewPanel videoPanel;
	
	private boolean mouseOver;
	
	//------------------------------------------------------ CONSTRUCTEURS --//
	
	public VideoInfoPanel(VideoStream video) {
		this.videoPanel = new PreviewPanel(video);
		
		setLayout(new BorderLayout());
		
		// Lanel contenant les informations sur la vidéo
		JLabel info = new JLabel("<html><center><b>" + video.getName() + "</b>" +
				"<br><small>" + InetTools.ipToString(video.getIp()) + ":" +
				video.getPort() + "</small></center></html>");
		info.setHorizontalAlignment(JLabel.CENTER);
		info.setFont(info.getFont().deriveFont(Font.PLAIN));
		info.setForeground(Color.WHITE);
		
		add(info, BorderLayout.SOUTH);
		add(videoPanel, BorderLayout.CENTER);
		
		setBorder(new EmptyBorder(10, 10, 10, 10));
		setOpaque(false);
		
		// Redessine le panel au survol de la souris
		addMouseListener(new MouseAdapter() {
			public void mouseEntered(MouseEvent e) {
				mouseOver = true;
				repaint();
			}
			
			public void mouseExited(MouseEvent e) {
				mouseOver = false;
				repaint();
			}
		});
	}
	
	//----------------------------------------------------------- METHODES --//
	
	public void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		
		if (mouseOver) {
			g2d.setRenderingHint(
					RenderingHints.KEY_ANTIALIASING,
					RenderingHints.VALUE_ANTIALIAS_ON);
			
			g2d.setPaint(new GradientPaint(new Point(0, 5), new Color(0x1a68d7),
					new Point(0, getHeight() - 5), new Color(0x76bfe2)));
			g2d.fillRoundRect(5, 5, getWidth() - 10, getHeight() - 10, 10, 10);
		}
	}
	
	public VideoStream getVideoStream() {
		return videoPanel.getVideoStream();
	}
	
	//--------------------------------------------------- METHODES PRIVEES --//
}
